#ifndef CACHEDDISTANCEMAP
#define CACHEDDISTANCEMAP

#include <queue>
#include <math.h>
#include <stdlib.h>
#include <string.h>

	typedef struct
	{
		int State;
		float Dist;
		int SrcI, SrcJ;
	} MapCell;

	typedef struct
	{
		float OriginX, OriginY;
		float Scale;
		int SizeX, SizeY;
		MapCell *Cells;
		float MaxDist;
	} DisMap;

	class CellData
	{
	public:
		DisMap* mpMap;
		unsigned int mnI, mnJ;
		unsigned int mnSrcI, mnSrcJ;
	};

	class CachedDistanceMap
	{
	public:
		CachedDistanceMap(float Scale, float MaxDist) :
	      mpDistances(NULL), mdScale(Scale), mdMaxDist(MaxDist) 
	    {
			mnCellRadius = MaxDist / Scale;
			mpDistances = new float *[mnCellRadius + 2];
			for (int i = 0; i <= mnCellRadius + 1; i++)
			{
				mpDistances[i] = new float[mnCellRadius + 2];
				for (int j = 0; j <= mnCellRadius + 1; j++)
				{
					mpDistances[i][j] = sqrt(i*i + j*j);
				}
			}
	    }
	    ~CachedDistanceMap()
	    {
			if(mpDistances)
			{
				for (int i = 0; i <= mnCellRadius + 1; i++)
				{
					delete[] mpDistances[i];
				}
				delete[] mpDistances;
			}
	    }
		float** mpDistances;
		float mdScale;
		float mdMaxDist;
		int mnCellRadius;
	};

#endif
